<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/step.css" media="all">
</head>
<body>
    <div class="layui-fluid">
        <div class="title-row">资材信息导入</div>
        <div class="layui-step" id="step">
            <div class="layui-step-content layui-clear">
                <div class="layui-step-content-item" style="background-color: #ECEDF2;margin: 15px auto 30px; padding: 24px;">
                    <div class="layui-row">
                        <div class="layui-col-md11">
                            <input id="searchText" type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
                        </div>
                        <div class="layui-col-md1" style="text-align:right;">
                            <button onclick="searchFMc()" id="searchBtn" class="layui-btn layuiadmin-btn-replys layui-icon layui-icon-search layuiadmin-button-btn" data-type="reload" lay-submit lay-filter="LAY-app-forumreply-search">
                               查询
                            </button>
                        </div>
                    </div>
                    <div class="layui-row layui-col-space10" style="margin-top: 16px" id="searchList">
                        <div class="layui-col-md4 " style="padding-left: 8px; padding-right: 8px;" >
                            <div class="importItem1 importItem"><ul></ul></div> 
                        </div>
                        <div class="layui-col-md4 " style="padding-left: 8px; padding-right: 8px;" >
                            <div class="importItem2 importItem"><ul> </ul></div>   
                        </div>
                        <div class="layui-col-md4 " style="padding-left: 8px; padding-right: 8px;" >
                            <div class="importItem3 importItem"><ul></ul></div> 
                        </div>
                    </div>
                </div>
                <div class="layui-step-content-item">
                    <div class="current-select" id = "showNameSpan"></div>
<!--                    <div class="select-file">-->
<!--                        <div class="input-file">-->
<!--                            <div class="input-group-prepend" style="padding: 0 20px; border-bottom-right-radius: 0px; border-top-right-radius: 0; border-right: 0;"><i class="layui-icon layui-icon-upload-circle"></i></div>-->
<!--                            <input type="text" placeholder="未选择文件" class="input-inner"/>-->
<!--                            <div class="input-group-prepend" style="padding: 0 20px; border-bottom-left-radius: 0; border-top-left-radius: 0; border-left: none;">-->
<!--                                点击上传 <input class="filePrew" type="file">-->
<!--                            </div>-->
<!--                        </div>-->
<!--                        <button type="button" class="layui-btn">-->
<!--                            <i class="layui-icon layui-icon-upload"></i>导入-->
<!--                        </button>-->
<!--                        <button type="button" class="layui-btn">-->
<!--                            <i class="layui-icon layui-icon-download-circle"></i>下载模板-->
<!--                        </button>-->
<!--                    </div>-->
                    <div class="import-bth">
                        <button type="button" class="layui-btn" id="import-excel"><i class="layui-icon"></i>导入excel
                        </button>
                        <button type="button" class="layui-btn" onclick="downloadCateTemplate()">
                            <i class="layui-icon layui-icon-download-circle" ></i>下载模板
                        </button>
                    </div>
                </div>
            </div>
                <div class="layui-step-btn">
                    <div class="layui-btn-group">
                        <button class="layui-btn prev">上一步</button>
                        <button class="layui-btn next">下一步</button>
                    </div>
                </div>
            </div>
    </div>
    <script src="../../layuiadmin/layui/layui.js"></script> 
    <script>
        var showIndex1,showIndex2,showIndexParent=0,fMcIdLast,fMcShowNameLast;
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
            }).extend({
                index: 'lib/index' //主入口模块
            , my_send: '../myModules/my_send'
            }).use(['index', 'form','step','upload','my_send'], function(){
                var $ = layui.$
                ,step = layui.step
                ,form = layui.form
                ,upload = layui.upload
                ,my_send = layui.my_send
                , http_proxy = layui.http_proxy;
                step.render({
                elem: '.layui-step',
                isOpenStepLevel: true,
                title:["选择分类","导入"]
            });
            $(".prev").on("click",function() {
                step.prev();
            });
            $(".next").on("click",function() {
                step.next();
            });
            $.ajax({
                url: http_proxy('/mcIn/getFMcByParams'),
                type:'GET',
                datatype:'json',
                async:false,
                success:function(data){
                    var str = '';
                    $.each( data.grid.rows, function (i, item){
                        var indexParames = item.fMcShowName+'!#!%!'+item.fMcId+'!#!%!'+item.fParent;
                        str += '<li onclick = demoTest("'+indexParames+'");>' +item.fMcShowName + '<i class="layui-icon layui-icon-next"></i></li>'
                    })
                    $('.importItem1 ul').html(str);
                    
                }
            })

            //文件上传
            //Excel导入
            upload.render({
                elem: '#import-excel'
                , url: http_proxy('/mcIn/importProduct')
                , accept: 'file' //普通文件
                ,exts:'xls'
                ,size:1024
                , type: "json"
                , before: function (obj) {
                    layer.msg("请求中。。。请稍后.",{icon: 6, time: 4000})
                }
                , done: function (data) {
                    layer.closeAll("loading");
                    console.log(data);
                    if (data.code == "success") {
                        var msg = "状态："+data.code+","+data.msg;
                        layer.msg(msg, {icon: 6, time: 4000});
                        // layer.msg();
                        table.reload('pallet-table', {page: {curr: 1}});
                    } else {
                        layer.msg("状态：" + data.code+","+data.msg, {icon: 5,time: 4000});
                    }
                }
            });
        });
        function demoTest(id){
            var $ = layui.$
            var paramesArrIndex = id.split('!#!%!');
            showIndexParent=paramesArrIndex[3];
            $('.importItem3 ul').empty();
            console.log($(this))
            $(this).addClass('active');
            $.ajax({
                url: http_proxy('/mcIn/getFMcByParams?fMcShowName=&fParent=') + paramesArrIndex[1],
                type:'GET',
                datatype:'json',
                async:false,
                success:function(data){
                    var str = '';
                    fMcShowNameLast=paramesArrIndex[0];
                    fMcIdLast=paramesArrIndex[1];
                    $("#showNameSpan").html('当前选中为：'+paramesArrIndex[0]);
                    $.each( data.grid.rows, function (i, item){
                        var parames = item.fMcShowName+"-***-"+item.fMcId+'-***-'+item.fParent;
                        str += '<li onclick = demoTestt("'+ parames +'")>' +item.fMcShowName + '<i class="layui-icon layui-icon-next"></i></li>'
                    })
                    $('.importItem2 ul').html(str);
                    showIndex1=paramesArrIndex[0];
                }
            })
        }
        function demoTestt(idd){
            var $ = layui.$
            $(this).addClass('active');
            var paramesArr = idd.split('-***-');
            showIndexParent = paramesArr[3];
            $.ajax({
                url: http_proxy('/mcIn/getFMcByParams?fMcShowName=&fParent=') + paramesArr[1],
                type:'GET',
                datatype:'json',
                async:false,
                success:function(data){
                    fMcShowNameLast=paramesArr[0];
                    fMcIdLast=paramesArr[1];
                    $("#showNameSpan").html('当前选中为：'+paramesArr[0]);
                    var str = '';
                    $.each( data.grid.rows, function (i, item){
                        var parames1 = item.fMcShowName+"-***-"+item.fMcId;
                        str += '<li onclick = demoTesttt("'+ parames1 +'")>' +item.fMcShowName + '<i class="layui-icon layui-icon-next"></i></li>'
                    })
                    $('.importItem3 ul').html(str);
                    showIndex2=paramesArr[0];
                }
            })
        }
            
        
        function downloadCateTemplate(){
            let params = "?fMcId=" + fMcIdLast + "&fMcShowName=" + fMcShowNameLast;
            window.location.href = http_proxy("/mcIn/downloadCateTemplate") + params;
        }
        function searchFMc(){
            var $ = layui.$
            var searchStr = $("#searchText").val();
            $('.importItem1 ul').empty();
            $('.importItem2 ul').empty();
            $('.importItem3 ul').empty();
            $.ajax({
                url: http_proxy('/mcIn/getFMcByParams'),
                type:'GET',
                datatype:'json',
                async:false,
                data:{"fMcShowName":searchStr},
                success:function(data){
                    if(data.grid.rows==null||data.grid.rows==""){
                        $('.importItem1 ul').children().filter('li').remove();
                    }
                    var str = '';
                    $.each( data.grid.rows, function (i, item){
                        str += '<li>' +item.fMcShowName + '<i class="layui-icon layui-icon-next"></i></li>'
                        if(item.fLevel == 0){
                            $('.importItem1 ul').append(str);
                            var indexParamesSearch1 = item.fMcShowName+'!#!%!'+item.fMcId+'!#!%!'+item.fParent;
                            $('.importItem1 ul li').attr("onclick","demoTest("+"'"+indexParamesSearch1+"'"+")");
                        }else if(item.fLevel == 1){
                            $('.importItem2 ul').append(str);
                            var indexParamesSearch2 = item.fMcShowName+'-***-'+item.fMcId+'-***-'+item.fParent;
                            $('.importItem2 ul li').attr("onclick","demoTestt("+"'"+indexParamesSearch2+"'"+")");
                        }else{
                            $('.importItem3 ul').append(str);
                            var indexParamesSearch3 = item.fMcShowName+'-***-'+item.fMcId+'-***-'+item.fParent;
                            $('.importItem3 ul li').attr("onclick","demoTesttt("+"'"+indexParamesSearch3+"'"+")");
                        }
                    })
                    // $('.importItem3 ul').html(str);
                }
            })
        }




        function demoTesttt(parames1){
            var $ = layui.$;
            var paramesArry1 = parames1.split('-***-');
            showIndexParent = paramesArry1[3];
            fMcShowNameLast=parames1[0];
            fMcIdLast=parames1[1];
            $("#showNameSpan").html('当前选择为：'+showIndex1+'/'+showIndex2+'/'+paramesArry1[0]);
        }
    </script>
    <script>
        var card = document.getElementById('label');
        function getFileSize(v) {
            card.value = v;
            console.log(v)
        }
    </script>
</body>
</html>